/*
 * 官网主JS
 * 20250707
 * */
function isMobile() {
  var plat = null
  let n = navigator.userAgent
  if (n.indexOf('Android') > -1 || n.indexOf('Linux') > -1) {
    plat = 'android'
  } else if (n.indexOf('iPhone') > -1) {
    plat = 'ios'
  } else {
    plat = ''
  }
  return plat
}

$(function () {
  // 智能下载按钮初始化
  function initSmartDownload() {
    const smartBtn = $('#smartDownloadBtn');
    const smartIcon = $('#smartIcon');
    const smartTitle = $('#smartTitle');
    const smartSubtitle = $('#smartSubtitle');
    
    // 检测设备类型
    const userAgent = navigator.userAgent;
    let deviceType = '';
    let downloadUrl = '#';
    let iconText = '📱';
    let titleText = '立即下载';
    let subtitleText = '';
    
    if (/iPad|iPhone|iPod/.test(userAgent)) {
      // iOS设备
      deviceType = 'ios';
      iconText = '🍎';
      titleText = 'App Store下载';
      subtitleText = 'iOS版本';
      downloadUrl = 'https://apps.apple.com/us/app/%E5%A5%BD%E6%BB%A1%E8%B4%AD/id6742049757';
    } else if (/Android/.test(userAgent)) {
      // Android设备
      deviceType = 'android';
      iconText = '🤖';
      titleText = '安卓下载';
      subtitleText = 'Android版本';
      downloadUrl = 'https://www.jingyunwangluo.com/apk/beibeiyouxuan.apk';
    } else {
      // 其他设备（桌面等）
      deviceType = 'other';
      iconText = '💻';
      titleText = '手机扫码下载';
      subtitleText = '获取手机版';
      downloadUrl = '#';
    }
    
    // 更新按钮内容
    smartIcon.text(iconText);
    smartTitle.text(titleText);
    smartSubtitle.text(subtitleText);
    smartBtn.attr('href', downloadUrl);
    
    // 添加点击事件
    smartBtn.off('click').on('click', function(e) {
      if (downloadUrl === '#') {
        e.preventDefault();
        // 可以在这里显示二维码或其他操作
        alert('请使用手机访问或扫描二维码下载');
      }
    });
  }
  
  function hashFn(callback) {
    var hashchange = 'hashchange',
      DOC = document,
      documentMode = DOC.documentMode,
      supportHashChange = 'on' + hashchange in window && (documentMode === void 0 || documentMode > 7)
    if (!supportHashChange) {
      return false
    }
    $(window)
      .off(hashchange)
      .on(hashchange, function () {
        var _h = window.location.hash.replace('#', '')
        callback(_h)
      })
    $(window).trigger(hashchange)
  }

  var hashCurr = ''
  hashFn(function (h) {
    hashCurr = h
    //视频处理
    if (h === 'Contact') {
      //	img/join_bg.mp4
      
    } else {
      
    }
    if (h) {
      // $(".navBox li a[data-id=" + h + "]").closest('li').addClass('active').siblings('li').removeClass('active');
      // $('#wrap')[0].className = 'g_wrap wrap' + h;
      // $(".g_pointDiv a[href=#" + h + "]").addClass('active').siblings().removeClass('active');
    }
    // if(!h || h === 'Home'){
    // 	$(".homeBannerBox .p1").addClass('bg');
    // }
  })
  // 初始化智能下载按钮
  initSmartDownload();
  

  
  if ($('#main').length > 0) {
    $('#main').fullpage({
      navigation: true,
      resize: true,
      verticalCentered: true,
      scrollOverflow: true,
      menu: '#menu',
      anchors: ['Home', 'Home2', 'Home3', 'Home4', 'About', 'Contact'],
      // anchors: ['Home', 'About', 'News', 'Notice', 'Join'],
      onLeave: function (index, nextIndex, direction) {
        //	滚动前的回调函数，接收 index、nextIndex 和 direction 3个参
        // console.log('-----',index,nextIndex,direction)
        $('.g_pointDiv a')
          .eq(nextIndex - 1)
          .addClass('active')
          .siblings()
          .removeClass('active')
        if (nextIndex <= 4) {
          $('.navBox li a[data-id=Home]').closest('li').addClass('active').siblings('li').removeClass('active')
          $('#homeDownDiv').fadeIn()
        } else if (nextIndex === 5) {
          // About页面，激活第2个导航项 "关于我们"
          $('.navBox li').eq(1).addClass('active').siblings('li').removeClass('active')
          $('#homeDownDiv').fadeOut()
        } else if (nextIndex === 6) {
          // Contact页面，激活第3个导航项 "联系我们"
          $('.navBox li').eq(2).addClass('active').siblings('li').removeClass('active')
          $('#homeDownDiv').fadeOut()
        }
      },
      afterLoad: function (anchorLink, index) {
        if (anchorLink === 'Contact') {
          $('#head').addClass('bg')
          $('.mapBox').addClass('bg')
          $('#g_msgDiv').fadeOut()
        } else {
          $('#head').removeClass('bg')
          $('#g_msgDiv').fadeIn()
        }
        if (anchorLink.indexOf('Home') > -1) {
          $('#wrap')[0].className = 'g_wrap wrapHome'
        } else {
          $('#wrap')[0].className = 'g_wrap wrap' + anchorLink
        }

        // $(".navBox li").eq(index-1).addClass('active').siblings('li').removeClass('active');
        // console.log('anchorLink',anchorLink,index)
      }
    })

    //解决导航的隐藏高度过高，点击空白区域会导致滚动条无法滚动的BUG
    $('#head').on('click', function () {
      $('.joinBanner').trigger('click')
    })
  }
})
